/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using System.ComponentModel;
using System.Windows.Forms.Design;
using System.Windows.Forms;

namespace DaveSexton.DocProject.ExternalUI
{
	internal sealed class ProgramServices : IServiceProvider
	{
		#region Public Properties
		public IUIService UIService
		{
			get
			{
				if (uiService == null)
					uiService = new UIService(owner);

				return uiService;
			}
		}
		#endregion

		#region Private / Protected
		private IUIService uiService;
		private readonly ProgramForm owner;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="ProgramServices" /> class.
		/// </summary>
		public ProgramServices(ProgramForm owner)
		{
			if (owner == null)
				throw new ArgumentNullException("owner");

			this.owner = owner;
		}
		#endregion

		#region IServiceProvider Members
		public object GetService(Type serviceType)
		{
			if (serviceType == null)
				return null;
			else if (serviceType == typeof(IUIService))
				return UIService;
			else
			{
				ISite site = owner.Site;

				if (site != null)
					return site.GetService(serviceType);
				else
					return null;
			}
		}
		#endregion
	}
}
